import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-s-home' }
    }]
  },

  {
    path: '/business',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '业务模块', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'bulletMsg',
        name: 'bulletMsg',
        component: () => import('@/views/business/bulletMsg'),
        meta: { title: '弹幕管理', icon: 'el-icon-reading' }
      },
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/business/user'),
        meta: { title: '用户管理', icon: 'el-icon-user-solid' }
      },
      { 
        path: 'video',
        name: 'Video',
        component: () => import('@/views/business/video'),
        meta: { title: '视频管理', icon: 'el-icon-s-custom' }
      },
      {
        path: 'reportTable',
        name: 'reportTable',
        component: () => import('@/views/business/reportTable'),
        meta: { title: '弹幕举报管理', icon: 'el-icon-sunrise-1' }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '系统模块', icon: 'el-icon-s-platform' },
    children: [
      {
        path: 'employee',
        name: 'employee',
        component: () => import('@/views/system/employee'),
        meta: { title: '员工管理', icon: 'el-icon-s-custom' }
      },
      {
        path: 'department',
        name: 'department',
        component: () => import('@/views/system/department'),
        meta: { title: '部门管理', icon: 'el-icon-menu' }
      },
      // {
      //   path: 'departmentCount',
      //   name: 'departmentCount',
      //   component: () => import('@/views/system/departmentCount/index.vue'),
      //   meta: { title: '部门统计', icon: 'el-icon-s-data' }
      // },
      {
        path: 'bulletMsgSensitive',
        name: 'BulletMsgSensitive',
        component: () => import('@/views/system/bulletmsgsensitive'),
        meta: { title: '弹幕敏感字管理', icon: 'el-icon-receiving' }
      },
      {
        path: 'configInfo',
        name: 'configInfo',
        component: () => import('@/views/system/configInfo/index.vue'),
        meta: { title: '系统配置', icon: 'el-icon-setting' }
      },
      {
        path: 'loginLogger',
        name: 'loginLogger',
        component: () => import('@/views/system/loginLogger/index.vue'),
        meta: { title: '登录日志', icon: 'el-icon-document' }
      }
    ]
  },


  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://wolfcode.cn',
        meta: { title: '小狼直播官网', icon: 'link' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
